// 引入文件进行正则匹配
var util = require("../../utils/util.js");
import { SA } from '../../selectarea/selectarea';
const conf = {
    data: {
        addressBox:'',
        province:'',
        city:'',
        county:'',
        phone:'',
        address:'',
        name:'',
        uid:''
    },
    onLoad: function (options) {
        console.log(options)
        var that = this;
        that.setData({
            uid:options.uid
        })
        SA.load(this); // 初始化区域框
        wx.setNavigationBarTitle({
      title: '服务地址'
        })
    },
    choosearea() { // 页面弹框触发事件
        SA.choosearea(this); 
    },
    addDot() { // 字符串截取
        SA.addDot(this);
    },
    tapProvince(e) { // 点击省份
        SA.tapProvince(e, this);
    },
    tapCity(e) { // 点击城市
        SA.tapCity(e, this);
    },
    tapDistrict(e) { // 点击区域
        SA.tapDistrict(e, this);
    },
    cancel() { // 取消选择
        SA.cancel(this);
    },
    confirm(e) { // 确认选择区域
        SA.confirm(e, this);
    },
// 获取信息  收货人 地址  电话
name:function(e){
this.setData({
    name:e.detail.value
})
},
phone:function(e){
this.setData({
    phone:e.detail.value
})
},
address:function(e){
this.setData({
    address:e.detail.value
})
},
submit:function(){
console.log(this.data.name)
var that= this
var flag = util.checkPhoneNum(this.data.phone, that);
var text = '';
if(this.data.name == ''){
    text = '请输入收货人姓名'
}else if(this.data.addressBox == ''){
text = '请输入所在区域'
}else if(this.data.address == ''){
text = '请输入详地址'
}else if(!flag){
    // console.log(phone.test(this.data.newPhone))
text = '请输入正确的电话号码'
}
if(text!=''){
  wx.showModal({
        content: text,
        showCancel: false,
      });
}else {
wx.request({
    url: "http://1.aiym.applinzi.com/aiyouwai.php",
    data: {
      type: "insertAddress",
      paras: {
        uid: that.data.uid,
        linkMan:that.data.name,
        linkPhone:that.data.phone,
        detailAddress:that.data.address,
        region:that.data.province+'-'+that.data.city+'-'+that.data.county
      }
    },
    header: { "content-type": "application/json" },
    success: function (res) {
     wx.navigateBack({
       delta: 1, // 回退前 delta(默认为1) 页面
       
     })
    }
  })
}
}
}

Page(conf);